package com.itheima.examination1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Stream;

public class ProvinceStatistics2 {
    public static void main(String[] args) {
        String[] provinces = {"河北省", "山西省", "吉林省", "辽宁省",
                "黑龙江省", "陕西省", "甘肃省", "青海省", "山东省", "福建省", "浙江省",
                "台湾省", "河南省", "湖北省", "湖南省", "江西省", "江苏省", "安徽省",
                "广东省", "海南省", "四川省", "贵州省", "云南省", "北京市", "天津市",
                "上海市", "重庆市", "内蒙古自治区", "新疆维吾尔自治区", "宁夏回族自治区",
                "广西壮族自治区", "西藏自治区", "香港特别行政区", "澳门特别行政区"};

        //1.
        long count = Arrays.stream( provinces)
                .filter(c -> c.length() == 3)
                .count();
        System.out.println("三个字的省份个数: " + count);

        //2.
        long count1 = Stream.of(provinces)
                .filter(c -> c.contains("东")||c.contains("西")||c.contains("南")||c.contains("北"))
                .count();
        System.out.println("包含方位词的省份个数: " + count1);

        //3.
        Stream.of(provinces)
                .filter(c -> c.contains("东")||c.contains("西")||c.contains("南")||c.contains("北"))
                .filter(c -> c.endsWith("省"))
                .forEach(System.out::println);

        //4.
        Object[] array = Stream.of(provinces)
                .filter(c -> c.endsWith("省"))
                .toArray();
        System.out.println(Arrays.toString( array));
    }
}
